{% extends 'base.html' %}

{% block title %}Manage Links{% endblock %}

{% block content %}
    <div class="page-header">
        <h1>Manage Links
            <small class="text-muted">{{ links | length }}</small>
            <a class="btn btn-sm btn-primary" style="float:right;"
               href="{{ url_for('admin.new_link') }}">
                New Link
            </a>
        </h1>
    </div>
    <div class="page-footer">
        <table class="table table-striped table-secondary">
            <thead>
            <tr>
                <th>No.</th>
                <th>Name</th>
                <th>URL</th>
                <th>Actions</th>
            </tr>
            </thead>
            {% for link in links %}
            <tr>
                <td>{{ loop.index }}</td>
                <td>{{ link.name }}</td>
                <td>
                    <a href="{{ link.url }}" target="_blank">{{ link.url }}</a>
                </td>
                <td>
                    <a href="{{ url_for('admin.edit_link', link_id=link.id) }}" class="btn btn-sm btn-success">Edit</a>
                    <form action="{{ url_for('admin.delete_link', link_id=link.id) }}" method="post" class="inline">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <button type="submit" class="btn btn-sm btn-danger">Delete</button>
                    </form>
                </td>
            </tr>
            {% endfor %}
        </table>
    </div>
{% endblock %}